<?php 
 if (!isset($_SESSION['login']) || !isset($_SESSION['senha'])) {
 	header('location: login.html');
 }
   if($_SESSION['permissao'] === '1' || $_SESSION['permissao'] === '3'){
 	   	 header('location: index.php');
 	   }
	if (isset($_GET['alert']) && !empty($_GET['alert'])) {
		$alert =$_GET['alert'];
		echo "<script type='text/javascript'>alert('$alert');</script>";
	}

	$sql = "SELECT * FROM funcionario ORDER BY dt_inscricao DESC";
	$resultado = mysql_query($sql);
?>
 <html>
 <head>
 <script type="text/javascript">
 	function paint (id) {
		
		for (var i = 0; i < id; i++) {
			if (i % 2 == 0) {
				document.getElementById(i).style.backgroundColor='#E6F9F7';
			}else{
				document.getElementById(i).style.backgroundColor='#BED6F4';
			}
		}
	}

	function excluir(id){
		var resp = confirm("Deseja 	realmente exluir o registro ?");

		if(resp){
			location.href="index.php?page=funcionario/excluirfuncionario.php&id="+id;
		}
	}
 </script>
 </head>

 <body>
	<div class="flist">
		<table class="tabela">
	 		 <tr>
                     <th colspan="5">Lista de Funcionários</th>
             </tr>
			<tr>
				<th>Matricula</th>
				<th>Nome</th>
				<th>Função</th>
				<th>Data de Inscrição</th>
				<th>Opções</th>
			</tr>
	  				<?php $i = 0;?>
			<?php 	while($arrayResult = mysql_fetch_assoc($resultado)): ?>	
					<?php if ($arrayResult['ativo'] == "1"): //caso o funcionario seja ativo! ?> 
										
					<tr id="<?php echo $i; ?>">
						<td><?php echo $arrayResult['matricula']; ?></td>
						<td><?php echo $arrayResult['no_funcionario']; ?></td>
						<td><?php 
						$sqlfun = "SELECT * FROM funcao";
						$resultFun = mysql_query($sqlfun);
						$arRefun = mysql_fetch_assoc($resultFun);
						do{
						if($arRefun['idfuncao'] == $arrayResult['idfuncao']){
							   echo $arRefun['descricaofunc'];
							}
						}while($arRefun = mysql_fetch_assoc($resultFun))?></td>
						<td><?php 
								$data = $arrayResult['dt_inscricao'];
								$dataformatada = new DateTime($data);
								$date = $dataformatada->format('d/m/Y');
								$time = $dataformatada->format('H:i:s');
								echo $date." &nbsp".$time;
								//echo $arrayResult['dt_inscricao'];
								?></td>
						<td>
							<a href="index.php?page=funcionario/editarfuncionario.php&id=<?php echo $arrayResult['matricula']?>">
								  <img src="imagens/pen2.png" height="32" width="32"/>
							</a> &nbsp &nbsp	
							<a href="#" onClick='excluir(<?php echo $arrayResult['matricula']; ?>)'>
								  <img src="imagens/exc.png" height="32" width="32" />
							</a>	
						</td>
					</tr>
					<?php $i++; ?>
					<?php endif ?>
			<?php endwhile; ?>
			<script type="text/javascript">
				var i = '<?php echo $i; ?>'; 
				paint(i);
			</script>
		</table>
	</div>
 </body>
 </html>